package com.bawei.module_base.ui.view

import android.view.View
import androidx.annotation.NonNull

import androidx.viewpager.widget.ViewPager


/**
 * 下弧形切换效果
 */
class ArcDownTransformer : ViewPager.PageTransformer {
    private val mMaxRotate = DEF_MAX_ROTATE
    override fun transformPage(@NonNull page: View, position: Float) {
        page.pivotY = page.height.toFloat()
        if (position < -1f) { //[-Infinity, -1)
            page.rotation = -mMaxRotate
            page.pivotX = page.width.toFloat()
        } else if (position <= 1f) { //[-1, 1]
            if (position < 0f) { //[-1, 0)
                page.rotation = mMaxRotate * position
                page.pivotX = page.width * (0.5f - 0.5f * position)
            } else { //[0, 1]
                page.rotation = mMaxRotate * position
                page.pivotX = page.width * (0.5f - 0.5f * position)
            }
        } else { //(1, +Infinity]
            page.rotation = mMaxRotate
            page.pivotX = 0f
        }
    }

    companion object {
        private const val DEF_MAX_ROTATE = 12.0f
    }
}
